﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Media;
using System.Windows.Controls;


namespace WpfEffect
{
    /// <summary>
    /// xiaokang 常用的工具代码
    /// </summary>
    public class CommonHelper
    {

        #region windows调色板取颜色
        public static Color GetWindowColor(Label lblColor)
        {
            Color c = Colors.White;
            System.Windows.Forms.ColorDialog cd = new System.Windows.Forms.ColorDialog();
            cd.AllowFullOpen = true;
            cd.AnyColor = true;

            if (lblColor.Background != null)
            {
                SolidColorBrush b = (SolidColorBrush)lblColor.Background;
                cd.Color = CommonHelper.ConvertToDrawFromMedia(b.Color);
            }

            if (cd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                c = CommonHelper.ConvertToMediaFromDrawing(cd.Color);
                lblColor.Background = new SolidColorBrush(c);
            }

            return c;
        }


        #endregion

        /// <summary>
        /// 颜色转换
        /// </summary>
        /// <param name="c"></param>
        /// <returns></returns>
        public static Color ConvertToMediaFromDrawing(System.Drawing.Color c)
        {
            return Color.FromArgb(c.A, c.R, c.G, c.B);
        }

        public static System.Drawing.Color ConvertToDrawFromMedia(Color c)
        {
            return System.Drawing.Color.FromArgb(c.A, c.R, c.G, c.B);
        }
    }
}
